package cn.edu.zsc.rbac.view;
import cn.edu.zsc.rbac.util.SingletonFactory;

import java.util.Scanner;

public class MainView {
    //定义静态变量用于输入
    public static Scanner input;
    //静态代码块初始化scanner对象
    static{
        input=new Scanner(System.in);
    }
    private final DeptView deptView;
    private final RoleView roleView;
    private final UserView userView;
    private MainView() {
        deptView = SingletonFactory.getInstance(DeptView.class);
        roleView = SingletonFactory.getInstance(RoleView.class);
        userView = SingletonFactory.getInstance(UserView.class);
    }
    /**
     * 输出管理部门菜单
     */
    public static final String MENU= """
              ———————————————————————
                     RBAC系统
              ———————————————————————
               |     0...退出系统    |
               |     1...部门管理    |
               |     2...角色管理    |
               |     3...用户管理    |
              ———————————————————————
              请输入选项:""";

    public void show() {
        String menuChoice;
        do {
            System.out.print(MENU);
            menuChoice = input.nextLine();
            switch (menuChoice) {
                case "0" -> System.out.println("成功退出系统，欢迎再次使⽤！");
                case "1" -> deptView.show();
                case "2" -> roleView.show();
                case "3" -> userView.show();
                default -> System.out.println("输⼊⾮法，请输⼊正确的菜单编号！");
            }
        } while (!"0".equals(menuChoice));
        input.close();
    }
}
